Hệ thống quản lý thanh toán POS nhà hàng

1 Imports System.Data.OleDb
2 Public Class frmInventoryType
3
4     Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
5         Me.Close()
6     End Sub
7     Sub Reset()
8         txtInventoryType.Text =
""
9         btnSave.Enabled = True
10         btnDelete.Enabled = False
11         btnUpdate.Enabled = False
12         txtInventoryType.Focus()
13     End Sub
14     Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
15         Reset()
16     End Sub
17
18     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
19         If txtInventoryType.Text =
"" Then
20             MessageBox.Show(
"Please enter Inventory Type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
21             txtInventoryType.Focus()
22             Return
23         End If
24
25         Try
26             con = New OleDbConnection(cs)
27             con.Open()
28             Dim ct As String =
"select type from InventoryType where type=@d1"
29             cmd = New OleDbCommand(ct)
30             cmd.Parameters.AddWithValue(
"@d1", txtInventoryType.Text)
31             cmd.Connection = con
32             rdr = cmd.ExecuteReader()
33
34             If rdr.Read() Then
35                 MessageBox.Show(
"Inventory Type Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
36                 txtInventoryType.Text =
""
37                 txtInventoryType.Focus()
38                 If (rdr IsNot Nothing) Then
39                     rdr.Close()
40                 End If
41                 Return
42             End If
43
44             con = New OleDbConnection(cs)
45             con.Open()
46             Dim cb As String =
"insert into InventoryType(type) VALUES (@d1)"
47             cmd = New OleDbCommand(cb)
48             cmd.Parameters.AddWithValue(
"@d1", txtInventoryType.Text)
49             cmd.Connection = con
50             cmd.ExecuteReader()
51             con.Close()
52             con = New OleDbConnection(cs)
53             con.Open()
54             Dim st As String =
"added the new Inventory Type '" & txtInventoryType.Text & "'"
55             LogFunc(lblUser.Text, st)
56             MessageBox.Show(
"Successfully Saved", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
57             btnSave.Enabled = False
58             Getdata()
59             Reset()
60         Catch ex As Exception
61             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
62         End Try
63     End Sub
64
65     Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
66         If txtInventoryType.Text =
"" Then
67             MessageBox.Show(
"Please enter Inventory Type", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
68             txtInventoryType.Focus()
69             Return
70         End If
71
72         Try
73
74             con = New OleDbConnection(cs)
75             con.Open()
76
77             Dim cb As String =
"Update InventoryType set type=@d1 where type=@d2"
78             cmd = New OleDbCommand(cb)
79             cmd.Connection = con
80             cmd.Parameters.AddWithValue(
"@d1", txtInventoryType.Text)
81             cmd.Parameters.AddWithValue(
"@d2", txtType.Text)
82             cmd.ExecuteReader()
83             con.Close()
84             Dim st As String =
"updated the Inventory Type '" & txtInventoryType.Text & "'"
85             LogFunc(lblUser.Text, st)
86             MessageBox.Show(
"Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
87             btnUpdate.Enabled = False
88             Getdata()
89         Catch ex As Exception
90             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
91         End Try
92     End Sub
93     Private Sub DeleteRecord()
94
95         Try
96             Dim RowsAffected As Integer =
0
97             con = New OleDbConnection(cs)
98             con.Open()
99             Dim cl As String =
"select Type from R_Table,InventoryType where R_Table.InventoryType=InventoryType.Type and Type=@d1"
100             cmd = New OleDbCommand(cl)
101             cmd.Connection = con
102             cmd.Parameters.AddWithValue(
"@d1", txtInventoryType.Text)
103             rdr = cmd.ExecuteReader()
104             If rdr.Read Then
105                 MessageBox.Show(
"Unable to delete..Already in use in Table Master", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
106                 If Not rdr Is Nothing Then
107                     rdr.Close()
108                 End If
109                 Exit Sub
110             End If
111             con.Close()
112             con = New OleDbConnection(cs)
113             con.Open()
114             Dim cl1 As String =
"select Type from Dish,InventoryType where Dish.InventoryType=InventoryType.Type and Type=@d1"
115             cmd = New OleDbCommand(cl1)
116             cmd.Connection = con
117             cmd.Parameters.AddWithValue(
"@d1", txtInventoryType.Text)
118             rdr = cmd.ExecuteReader()
119             If rdr.Read Then
120                 MessageBox.Show(
"Unable to delete..Already in use in Menu Items Entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
121                 If Not rdr Is Nothing Then
122                     rdr.Close()
123                 End If
124                 Exit Sub
125             End If
126             con.Close()
127             con = New OleDbConnection(cs)
128             con.Open()
129             Dim cq As String =
"delete from InventoryType where type=@d1"
130             cmd = New OleDbCommand(cq)
131             cmd.Parameters.AddWithValue(
"@d1", txtType.Text)
132             cmd.Connection = con
133             RowsAffected = cmd.ExecuteNonQuery()
134             If RowsAffected >
0 Then
135                 Dim st As String =
"deleted the Inventory Type '" & txtInventoryType.Text & "'"
136                 LogFunc(lblUser.Text, st)
137                 MessageBox.Show(
"Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
138                 Getdata()
139                 Reset()
140             Else
141                 MessageBox.Show(
"No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
142                 Reset()
143             End If
144             If con.State = ConnectionState.Open Then
145                 con.Close()
146
147             End If
148         Catch ex As Exception
149             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
150         End Try
151     End Sub
152     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
153         Try
154             If MessageBox.Show(
"Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
155                 DeleteRecord()
156             End If
157         Catch ex As Exception
158             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
159         End Try
160     End Sub
161
162     Private Sub dgw_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgw.MouseClick
163         Try
164             If dgw.Rows.Count >
0 Then
165                 Dim dr As DataGridViewRow = dgw.SelectedRows(
0)
166                 txtType.Text = dr.Cells(
0).Value.ToString()
167                 txtInventoryType.Text = dr.Cells(
0).Value.ToString()
168                 btnUpdate.Enabled = True
169                 btnDelete.Enabled = True
170                 btnSave.Enabled = False
171             End If
172         Catch ex As Exception
173             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
174         End Try
175     End Sub
176
177     Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
178         Dim strRowNumber As String = (e.RowIndex +
1).ToString()
179         Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
180         If dgw.RowHeadersWidth < Convert.ToInt32((size.Width +
20)) Then
181             dgw.RowHeadersWidth = Convert.ToInt32((size.Width +
20))
182         End If
183         Dim b As Brush = SystemBrushes.ControlText
184         e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
185
186     End Sub
187     Public Sub Getdata()
188         Try
189             con = New OleDbConnection(cs)
190             con.Open()
191             cmd = New OleDbCommand(
"SELECT RTRIM(type) from InventoryType order by type", con)
192             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
193             dgw.Rows.Clear()
194             While (rdr.Read() = True)
195                 dgw.Rows.Add(rdr(
0))
196             End While
197             con.Close()
198         Catch ex As Exception
199             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
200         End Try
201     End Sub
202
203     Private Sub frmtype_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
204         Getdata()
205     End Sub
206 End Class


Gõ tìm kiếm nhanh...